package com.abigdreamer.arkflow;

import java.util.HashMap;
import java.util.List;

import com.cat.util.TwoTuple;

public class ArkflowService implements IArkflowService {

	@Override
	public String convertJpdlDefineJsonToXml(String jpdlDefineJson) {
		TwoTuple<List<WorkflowNode>, WorkflowNode> workflowDefine = new WorkflowDefineAnalyzer().execute(jpdlDefineJson);
		
		List<WorkflowNode> states = workflowDefine.first;
		WorkflowNode workflow = workflowDefine.second;
		
		HashMap<String, String> idNameMap = new HashMap<String, String>();
		for (WorkflowNode state : states) {
			idNameMap.put(state.getProcessName(), state.getName());
		}
		
		String xml = new WorkflowJsonToXml().toXml(states, idNameMap, workflow);
		return xml;
	}

	@Override
	public String convertJpdlDefineXmlToJson(String jpdlDefineXml) {
		String json = new JpdlToJsonService().toJson(jpdlDefineXml);
		return json;
	}

}
